1. Field of the Invention
The present invention relates generally to an improved data processing system and in particular to rapidly processing mathematical operations. Still more particularly, the present invention relates to determining how to represent a number in a data processing system.
2. Description of the Related Art
A design choice faced by software and hardware developers for modern computers is the decision of how to store numbers. Numbers can be stored as byte arrays, as classes of an object-oriented program language such as, for example, the BigDecimal class of the Java™ programming language. (Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.) Numbers can also be represented using different numbering systems. Numbering systems include a base-two representation and a base-ten representation. Base-ten representation, also known as decimal representation, is the numbering scheme with which most people are familiar. Base-two representation, also known as binary representation, uses only two digits, zero and one, and is the numbering scheme used by most computer systems.
The choice of number representation is an important design point from a performance perspective. The choice of number representation is closely tied to the characteristics of the numbers being used in a computer operation. In many computers, base-two representation is used to compute numbers, but base-ten (more easily human-readable) representation is used for input. To accommodate this scheme, a particular number may be converted from base-ten representation to base-two representation. An operation is then performed on the number, and the resulting output is converted back into base-ten representation.
However, a problem that can arise when performing this translation is inaccuracies in the final output due to inaccuracies in the conversion of certain numbers from decimal format to base-two format and back to decimal format. To overcome this problem, numbers are often stored as a class of an object-oriented programming language, often as immutable BigDecimal objects of the Java programming language.
Multiple underlying representations are possible for a BigDecimal object. In situations where two BigDecimal objects of different representations are operated on, it becomes costly to switch representations for one of the objects. Hence selecting the right representation when constructing BigDecimal objects is important.